x = int(input("Введите число: "))
c = 0
n1 = 0
b1 = 0
n2 = 0
b2 = 0
n3 = 0
b3 = 0
n4 = 0
b4 = 0
n5 = 0
b5 = 0
n6 = 0
b6 = 0
n7 = 0
b7 = 0
n8 = 0
b8 = 0
n9 = 0
b9 = 0
b10 = 0
n10 = 0
for i in range(1000, 10000):
    if i != 10000:
        if x == i:
            c = c + 1
            break
if c == 0:
    print(0)
if c == 1:
    var1 = x % 10
    var2 = x % 100 // 10
    var3 = x % 1000 // 100
    var4 = x % 10000 // 1000
    var5 = x % 10000 // 100
    var6 = x % 10000 // 10
    var7 = x % 1000 // 10
    var8 = x % 1000
    var9 = x % 100
    for r1 in range(0, var1):
        if r1 != 0:
            b1 = var1 % r1
        if b1 == 0:
            n1 = n1 + 1
    if n1 == 2:
        pass
    else:
        var1 = 0

    for r2 in range(0, var2):
        if r2 != 0:
            b2 = var2 % r2
        if b2 == 0:
            n2 = n2 + 1
    if n2 == 2:
        pass
    else:
        var2 = 0

    for r3 in range(0, var3):
        if r3 != 0:
            b3 = var3 % r3
        if b3 == 0:
            n3 = n3 + 1
    if n3 == 2:
        pass
    else:
        var3 = 0

    for r4 in range(0, var4):
        if r4 != 0:
            b4 = var4 % r4
        if b4 == 0:
            n4 = n4 + 1
    if n4 == 2:
        pass
    else:
        var4 = 0

    for r5 in range(0, var5):
        if r5 != 0:
            b5 = var5 % r5
        if b5 == 0:
            n5 = n5 + 1
    if n5 == 2:
        pass
    else:
        var5 = 0

    for r6 in range(0, var6):
        if r6 != 0:
            b6 = var6 % r6
        if b6 == 0:
            n6 = n6 + 1
    if n6 == 2:
        pass
    else:
        var6 = 0

    for r7 in range(0, var7):
        if r7 != 0:
            b7 = var7 % r7
        if b7 == 0:
            n7 = n7 + 1
    if n7 == 2:
        pass
    else:
        var7 = 0

    for r8 in range(0, var8):
        if r8 != 0:
            b8 = var8 % r8
        if b8 == 0:
            n8 = n8 + 1
    if n8 == 2:
        pass
    else:
        var8 = 0

    for r9 in range(0, var9):
        if r9 != 0:
            b9 = var9 % r9
        if b9 == 0:
            n9 = n9 + 1
    if n9 == 2:
        pass
    else:
        var9 = 0

    for r10 in range(0, x):
        if r10 != 0:
            b10 = x % r10
        if b10 == 0:
            n10 = n10 + 1
    if n10 == 2:
        pass
    else:
        x = 0

    print(max(var1, var2, var3, var4, var5, var6, var7, x))